<template>
  <div class="course-user-page">
    <div class="head">全部隧道</div>
    <div class="select-button">
      <el-row>
        <el-col :span="12">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-input v-model="inputUserId" placeholder="请输入用户id"></el-input>
            </el-col>
            <el-col :span="12">
              <el-input v-model="inputAnotherId" placeholder="请输入另一方用户id"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="4" :offset="1">
          <el-select v-model="inputStatus" placeholder="选择隧道状态">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="3" :offset="1">
          <el-button type="primary" plain @click="pageTunnels()" >查询</el-button>
        </el-col>
        <el-col :span="3">
          <el-button  type="primary" icon="el-icon-search" @click="clear()">清空</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="student-list" style="display: flex;flex-direction: column;align-items: center">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="selection" width="55"  align="center">
        </el-table-column>
        <el-table-column fixed prop="id" label="隧道ID" min-width="50%" align="center">
        </el-table-column>
        <el-table-column prop="userId" label="用户ID" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column prop="userName" label="用户昵称" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column prop="anotherId" label="另一方用户ID" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column prop="anotherName" label="另一方昵称" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column prop="status" label="隧道类型" min-width="40%" align="center" >
          <template slot-scope="scope">
            <span v-if="scope.row.status=='0'">普通消息</span>
            <span v-else-if="scope.row.status=='1'">引用帖子</span>
            <span v-else-if="scope.row.status=='2'">问题</span>
            <span v-else-if="scope.row.status=='3'">观点</span>
            <span v-else-if="scope.row.status=='4'">回答</span>
          </template>
        </el-table-column>
        <el-table-column prop="gmtCreate" label="隧道开启时间" min-width="50%" align="center" >
        </el-table-column>
      </el-table>

      <div class="block" style="margin-top: 20px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[8, 10, 20, 40]"
          :page-size="8"
          layout="total, sizes, prev, pager, next, jumper"
          :total="parseInt(total)">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "StudentManageView",
  data() {
    return {
      total: 0,
      currentSize: 8,
      currentPage: 1,
      tunnelInfo: {
        id: null,
        name: "",
        phone: "",
        identity: "",
        roles: []
      },

      inputUserId: "",
      inputAnotherId: "",
      inputStatus: "",
      debounceClock: null,

      tableData: [],
      options: [{
        value: 0,
        label: '普通消息'
      }, {
        value: 1,
        label: '引用帖子'
      },{
        value: 2,
        label: '问题'
      },{
        value: 3,
        label: '观点'
      },{
        value: 4,
        label: '回答'
      }]
    };
  },
  mounted() {
    this.pageTunnels();
  },
  methods: {
    pageTunnels() {
      this.$api.pageTunnelList({
        pageSize: this.currentSize,
        pageNow: this.currentPage,
        userId: this.inputUserId || '',
        anotherId: this.inputAnotherId || '',
        status: this.inputStatus || '',
      })
        .then((res) => {
          let list = res.data.rows;
          this.total = res.data.totalPage
          console.log(this.total)
          this.tableData = list
        });
    },
    handleSizeChange(val) {
      this.currentSize = parseInt(val);
      this.pageTunnels();
    },
    handleCurrentChange(val) {
      this.currentPage = parseInt(val);
      this.pageTunnels();
    },
    //TODO:点击查看隧道聊天记录

    clear(){
      this.inputUserId = ''
      this.inputAnotherId = ''
      this.inputStatus = ''
      this.pagePosts();
    }
  },
};
</script>

<style scoped>
.course-user-page{
  margin-top: 20px;
  width: 100%;
}


.head {
  padding-bottom: 10px;
}

.select-button {
  padding: 10px 0;
}

.student-list {
  width: 100%;
  padding: 10px 0;
  display: flex;
}
</style>
